package com.xxx.springboot.enums;

import lombok.Getter;

import java.util.*;

/**
 * 周期类型枚举
 */
@Getter
public enum IntervalEnum {

    LAST_1_WEEK((short)1, "近1周", "w"),
    LAST_1_MONTH((short)2, "近1月", "m"),
    LAST_3_MONTH((short)3, "近3月", "q"),
    LAST_6_MONTH((short)4, "近6月", "hy"),
    LAST_1_YEAR((short)5, "近1年", "y"),
    LAST_2_YEAR((short)6, "近2年", "ty"),
    LAST_3_YEAR((short)7, "近3年", "try"),
    LAST_5_YEAR((short)8, "近5年", "fiy"),
    LAST_10_YEAR((short)11, "近10年", "tey"),
    FROM_THIS_YEAR((short)9, "今年以来", "sy"),
    FROM_FOUND((short)10, "成立以来", "se"),
    ;

    Short type;
    String name;
    String en;

    IntervalEnum(Short type, String name, String en) {
        this.type = type;
        this.name = name;
        this.en = en;
    }

    private static Set<Short> types = new HashSet<>();
    private static List<String> names = new ArrayList<>();
    private static Map<Short, IntervalEnum> map = new HashMap<>();
    static {
        IntervalEnum[] v = values();
        for (IntervalEnum t : v) {
            types.add(t.getType());
            names.add(t.getName());
            map.put(t.getType(), t);
        }
    }

    public static String getNameByType(Short type) {
        return map.get(type).getName();
    }

    public static String getEnByType(Short type) {
        return map.get(type).getEn();
    }

    public static Set<Short> getAllTypes() {
        return types;
    }

    public static List<String> getAllNames() {
        return names;
    }

    public static boolean checkIsExist(Short type) {
        return types.contains(type);
    }

    public static void main(String[] args) {
        System.out.println(getNameByType(IntervalEnum.LAST_1_MONTH.getType()));
        System.out.println(getAllTypes());
        System.out.println(getAllNames());
    }

}
